<template>
  <transition name="modal-fade">
    <div class="saleManager-mask" @click.self="close" v-if="show">
      <div class="saleManager transition__container">
        <div class="saleManager-header">
          <h3>{{$t('system.frameView.belongCustomerService')}}</h3>
          <button type="button" class="btn-text saleManager-close" @click="close">
            <i class="iconfont icon-fe-close"></i>
          </button>
        </div>
        <div class="saleManager-qrcode">
          <img :src="saleManagerQRCode" :alt="$t('system.frameView.belongCustomerService')"/>
          <p>
            {{$t('frameHeader.service.scanQrCodesConsult')}}
          </p>
        </div>
        <div class="saleManager-line"></div>
        <div class="saleManager-contact">
          <p>{{$t('frameHeader.service.serviceTel')}}</p>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
/* util */
import QRCode from 'qrcodejs2'

export default {
  name: 'sale-manager',
  inject: ['initData'],
  props: {
    // 是否显示组件
    show: {
      type: Boolean,
      default: false
    },
    qrcodeUrl: {
      type: String,
      default: ''
    },
    qrcode: {
      type: String,
      default: ''
    },
    serviceGroupUrl: {
      type: String,
      default: ''
    }
  },
  computed: {
    tenantType() {
      return this.initData.tenantType;
    },
    saleManagerQRCode() {
      return this.qrcodeUrl || `/files/getQrcode?fileName=${this.qrcode}`;
    }
  },
  methods: {
    close(){
      this.$emit('update:show', false)
    },
    createCode() {
      let url = this.serviceGroupUrl || ''
      
      if(!url) return
      
      this.$nextTick(() => {
        this.$refs.qrcode.innerHTML = ''
        new QRCode(this.$refs.qrcode, {
          text: url,
          width: 268,
          height: 268,
          colorDark: '#000000',
          colorLight: '#ffffff',
          correctLevel: QRCode.CorrectLevel.H
        })
      })
    }
  }
}
</script>

<style lang="scss">
.saleManager-mask{
  @include mask();
  z-index: 999;
  overflow: auto;
}

.saleManager{
  position: relative;
  margin: 100px auto 20px auto;

  background-color: #fff;
  width: 420px;
  box-shadow: 1px 1px 8px rgba(0,0,0,0.15);
  color: #333;
}

.saleManager-close{
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  padding: 0;
  
  border: none;
  background-color: transparent;
  color: #666;
  
  &:hover{
    color: #e84040;
  }
}

.saleManager-header{
  position: relative;
  padding: 12px 0;
  
  h3{
    text-align: center;
    margin: 0;
    font-size: 20px;
    line-height: 32px;
  }
}

.saleManager-qrcode{
  padding: 8px 0 28px 0;
  img{
    display: block;
    margin: 0 auto;
    width: 268px;
    height: 268px;
  }
  
  p{
    color: #797e89;
    text-align: center;
    font-size: 12px;
    margin: 10px 0 0 0;
  }
}

.saleManager-line{
  width: 420px;
  margin: 0 auto;
  height: 1px;
  background-color: #f4f7f5;
}

.saleManager-contact{
  padding: 10px 0 10px 110px;
  p{
    font-size: 14px;
    margin: 0;
    line-height: 24px;
    color: #797e89;
  }
}
</style>

